{layout name="layout" /}

<div class="Hui-article">
	<article class="cl pd-20">
		<form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
			<input type="hidden" name="id" value="{$data.id}">
			<div class="row cl">
				<label class="form-label col-xs-2 col-sm-2">
					<span class="c-red">*</span> 角色名称：</label>
				<div class="formControls col-xs-6 col-sm-2">
					<input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name"
						datatype="*4-16">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2">网站角色：</label>
				<div class="formControls col-xs-8 col-sm-9">
					{foreach $powers as $value}
					<dl class="permission-list">
						<dt>
							<label>
								<input type="checkbox" value="{$value.id}"
									<?php if(in_array($value['id'], $role_powers)){echo 'checked';}?> name="check[]"
									class="parents" id="user-Character-{$value.id}"> {$value.name}</label> </dt>
						<dd>
							{notempty name='value.child'} {foreach $value.child as $val}
							<dl class="cl permission-list2">
								<dt>
									<label class="">
										<input type="checkbox" value="{$val.id}"
											<?php if(in_array($val['id'], $role_powers)){echo 'checked';}?>
											name="check[]" class="childs" id="user-Character-{$value.id}-{$val.id}">
										{$val.name}</label>
								</dt>
								<dd>
									{notempty name='val.child'} {foreach $val.child as $vo}
									<label class="">
										<input type="checkbox" value="{$vo.id}"
											<?php if(in_array($val['id'], $role_powers)){echo 'checked';}?>
											name="check[]" id="user-Character-{$value.id}-{$val.id}-{$vo.id}">
										{$vo.name}</label>
									{/foreach} {/notempty}
								</dd>
							</dl>
							{/foreach} {/notempty}
						</dd>
					</dl>
					{/foreach}
				</div>
			</div>


			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2">备注：</label>
				<div class="formControls col-xs-8 col-sm-7">
					<textarea id="note" name="note" cols="" rows="" class="textarea" placeholder="备注...200个字符以内"
						dragonfly="true" onKeyUp="textarealength(this,200)">{$data.note}</textarea>
					<p class="textarea-numberbar">
						<em class="textarea-length">0</em>/200</p>
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<button type="submit" class="btn btn-success radius" id="admin-role-save" name="">
						<i class="Hui-iconfont">&#xe632;</i>&nbsp;确&nbsp;定&nbsp;</button>
					<button type="button" class="btn btn-default radius" onClick="window.history.back();">
						<i class="Hui-iconfont">&#xe66b;</i>&nbsp;取&nbsp;消&nbsp;</button>
				</div>
			</div>
		</form>
	</article>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
	$(function () {

		$(".childs").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		});
		$(".parents").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));

		});
		$(".permission-list2 dd input:checkbox").click(function(){
			var l =$(this).parent().parent().find("input:checked").length;
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
			if($(this).prop("checked")){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
			}
			else{
				if(l==0){
					$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
				}
				if(l2==0){
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
				}
			}
		});
		$("#form-admin-role-add").submit(function(){
			var name = $("#name").val();
			console.log('name');
			if (isNull(name)) {
				layer.msg('角色名不可为空',{
					'icon':5,
					'time': 1000,
				});
				return false;
			}
		});
	})
</script>
<!--请在上方写此页面业务相关的脚本-->